package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.WemediaUseMapper;
import com.heima.wemedia.service.WemediaUserService;
import org.springframework.stereotype.Service;

@Service("WemediaUserService")
public class WemediaUserServiceImpl extends ServiceImpl<WemediaUseMapper, WmUser> implements WemediaUserService {


    /**
     * 根据用户名查询自媒体用户
     *
     * @param name
     * @return
     */
    @Override
    public ResponseResult findByName(String name) {
        if (name == null)
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);

        LambdaQueryWrapper<WmUser> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(WmUser::getName, name);

        WmUser user = super.getOne(lambdaQuery);

        return ResponseResult.okResult(user);
    }

    /**
     * 保存自媒体用户
     *
     * @param wmUser
     * @return
     */
    @Override
    public ResponseResult saveUser(WmUser wmUser) {
        if (wmUser == null)
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);

        super.save(wmUser);


        return ResponseResult.okResult(wmUser);
    }
}
